{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="请输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
		</div>
	</form>
	<table class="layui-hide" id="coin_log" lay-filter="coin_log"></table>
</div>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
	</div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function feiniaoInit() {
		var table = layui.table,tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#coin_log',
			title: '金币流水列表',
			toolbar: '#toolbarDemo',
			url: '{:url("coin_log/datalist")}',
			page: true,
			limit: 20,
			cols: [
				[
				{
					fixed: 'left',
					field: 'id',
					title: '编号',
					align: 'center',
					width: 80
				},{
					field: 'nickname',
					title: '用户',
					align: 'center',
					width: 250
				},{
					field: 'type',
					title: '类型',
					align: 'center',
					width: 100,
					templet:function(d) {
						return d.type == 1 ? '<button type="button" class="layui-btn layui-btn-xs layui-btn-normal layui-bg-orange">增加</button>' : '<button type="button" class="layui-btn layui-btn-primary layui-btn-xs">减少</button>';
					}
				},{
					field: 'amount',
					title: '数目',
					align: 'center',
					width: 100
				},{
					field: 'balance',
					title: '余额',
					align: 'center',
					width: 100
				},{
					field: 'title',
					title: '标题',
				},{
					field: 'ip',
					title: 'IP',
					align: 'center',
					width: 100
				},{
					field: 'create_time',
					title: '添加时间',
					align: 'center',
					width: 150
				},{
					field: 'update_time',
					title: '更新时间',
					align: 'center',
					width: 150
				}				
				]
			]
		});
		
		//监听表头工具栏事件
		table.on('toolbar(coin_log)', function(obj){
			if (obj.event === 'add') {
				tool.side("{:url('coin_log/add')}");
				return false;
			}
		});

		//监听表格行工具事件
		table.on('tool(coin_log)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('{:url("coin_log/read")}?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('{:url("coin_log/edit")}?id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("{:url('coin_log/del')}", { id: data.id }, callback);
					layer.close(index);
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->